﻿// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "Custom/TransparentShader"
{
	Properties
	{
		_TMainTex("Texture", 2D) = "white"{}
		[HideInInspector] _TransparentColor("Color", Color) = (0,0,0,0)
		[HideInInspector] _AlphaColor("AlphaColor", Color) = (0,0,0,0)
		_AlphaThreshold("AlphaThreshold", Float) = 0.05
	}

		SubShader{
			Tags{ "RenderType" = "Transparent" "Queue" = "Transparent" }
			LOD 100
			Fog{ Mode Off }
			ZWrite Off
			ZTest Always
			Blend One One
			BlendOp Add

			Pass{
				CGPROGRAM
	#pragma vertex vert
	#pragma fragment frag
	#include "UnityCG.cginc"

			sampler2D _TMainTex;
			float4 _TMainTex_ST;

			fixed4 _TransparentColor;
			fixed4 _AlphaColor;
			float _AlphaThreshold;

			struct vIn {
				half4 vertex:POSITION;
				float2 texcoord:TEXCOORD0;
			};

			struct vOut {
				half4 pos:SV_POSITION;
				float2 texcoord:TEXCOORD0;
			};

			vOut vert(vIn v) {
				vOut o;
				UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
				o.pos = UnityObjectToClipPos(v.vertex);
				o.texcoord = TRANSFORM_TEX(v.texcoord, _TMainTex);
				return o;
			}

			fixed4 frag(vOut i) :COLOR{
				fixed4 texcol = tex2D(_TMainTex, i.texcoord);
				fixed4 color = _TransparentColor;
				float flag = step(texcol.a, _AlphaThreshold);//当a<=b时返回1，否则返回0
				color = _TransparentColor + flag * _AlphaColor;

				return color;
			}
			ENDCG
		}
	}
}
